package com.geovis.emergency.spd.biz.pc.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.geovis.emergency.spd.biz.pc.mapper.PcSchedulingEventSituationMapper;
import com.geovis.emergency.spd.biz.pc.mapper.PcSchedulingEventStatisticsMapper;
import com.geovis.emergency.spd.biz.pc.service.IPcSchedulingEventSituationService;
import com.geovis.emergency.spd.entity.pc.entity.PcSchedulingEventSituation;
import com.geovis.emergency.spd.entity.pc.entity.PcSchedulingEventStatistics;
import com.geovis.emergency.spd.entity.pc.pojo.enums.EventStatisticsTypeEnum;
import com.geovis.emergency.spd.entity.pc.pojo.vo.PcSchedulingEventVO;
import com.geovis.emergency.spd.entity.pc.pojo.vo.SchedulingEventStatisticsVO;
import org.springframework.stereotype.Service;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 应急预案指挥模块-指挥调度事件_事件概况 服务实现类
 * </p>
 *
 * @author Lonsho
 * @since 2022-10-25
*/

@Service
@RequiredArgsConstructor
@Slf4j
public class PcSchedulingEventSituationServiceImpl extends ServiceImpl<PcSchedulingEventSituationMapper, PcSchedulingEventSituation> implements IPcSchedulingEventSituationService {
    private final PcSchedulingEventStatisticsMapper schedulingEventStatisticsMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveDetail(PcSchedulingEventVO schedulingEventVO) {
        PcSchedulingEventSituation pcSchedulingEventSituation = new PcSchedulingEventSituation();
        pcSchedulingEventSituation.setEventId(schedulingEventVO.getEventId());
        if (ObjectUtil.isNull(schedulingEventVO.getEventId())){
            pcSchedulingEventSituation.setEventId(schedulingEventVO.getId());
        }
        pcSchedulingEventSituation.setContent(schedulingEventVO.getContent());
        pcSchedulingEventSituation.setDrillId(schedulingEventVO.getDrillId());
        baseMapper.insert(pcSchedulingEventSituation);
//        for (SchedulingEventStatisticsVO schedulingEventStatisticsVO : schedulingEventVO.getStatisticsList()) {
//            saveStatistics(pcSchedulingEventSituation.getDrillId(), pcSchedulingEventSituation.getEventId(),pcSchedulingEventSituation.getId(), schedulingEventStatisticsVO.getStatisticsType(), schedulingEventStatisticsVO.getStatisticsCount());
//        }
    }

//    private void saveStatistics(String drillId, String eventId,String situationId, String typeName, int number){
//        PcSchedulingEventStatistics pcSchedulingEventStatistics = new PcSchedulingEventStatistics();
//        pcSchedulingEventStatistics.setEventId(eventId);
//        pcSchedulingEventStatistics.setType(EventStatisticsTypeEnum.EVENT_SITUATION.getCode());
//        pcSchedulingEventStatistics.setDrillId(drillId);
//        schedulingEventStatisticsMapper.insert(pcSchedulingEventStatistics);
//    }
}
